class CategoriesController < ApplicationController
  def create
    @category = Category.new(params[:category])
    @category.user = user
    @category.save!

    if params[:subscriptions]

      Subscription.update( params[:subscriptions].keys,
                           params[:subscriptions].keys.
                           map{ |i|  { :category_id => @category.id} })
    end
    @title = @category.title
  end

  def destroy
    @category = Category.find(params[:id])
    @category.destroy
  end

  def show
    @category = Category.find(params[:id])
    @item_datas = @category.item_data
    @title = @category.title
  end

  def mark
    @category = Category.find(params[:id])
    @category.subscriptions.each do |subscription|
      subscription.unreadeds.clear
    end
  end

end
